package communication

import (
	"log"

	MQTT "github.com/eclipse/paho.mqtt.golang"
)

func MQTTConnect(broker string, clientID string, topic string) {
	opts := MQTT.NewClientOptions().AddBroker(broker).SetClientID(clientID)
	client := MQTT.NewClient(opts)
	if token := client.Connect(); token.Wait() && token.Error() != nil {
		log.Println("MQTT Connection Error:", token.Error())
		return
	}
	defer client.Disconnect(250)
	log.Println("MQTT Connection Established:", broker)

	// Publish/Subscribe example
	token := client.Subscribe(topic, 0, nil)
	token.Wait()
	log.Println("Subscribed to topic:", topic)

	// Add message handling logic here
}
